package com.jf.blog_jf04.controller;

import com.jf.blog_jf04.bean.Userinfo;
import com.jf.blog_jf04.data.PageInfo;
import com.jf.blog_jf04.data.dto.ExamDto;
import com.jf.blog_jf04.data.dto.UserinfoDto;
import com.jf.blog_jf04.data.ov.AuthOV;
import com.jf.blog_jf04.data.ov.ExamOV;
import com.jf.blog_jf04.data.ov.UserinfoSearchOV;
import com.jf.blog_jf04.service.UserinfoService;
import com.jf.blog_jf04.utils.BeanConvertUtils;
import com.jf.blog_jf04.utils.MyConstants;
import com.jf.blog_jf04.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/vip")
@RestController
@Api(tags = "会员模块")
public class VipController {
    @Autowired
    private UserinfoService userinfoService;

    @GetMapping("/page")
    @ApiOperation("分页筛选")
    public R page(PageInfo pageInfo, UserinfoSearchOV form) {
        form.setRoleId(MyConstants.ROLE_VIP);
        return userinfoService.getPage(pageInfo, form);
    }

    @DeleteMapping("/delete")
    @ApiOperation("批量删除")
    public R delete(@ApiParam("批量删除的id") @RequestParam List<Integer> ids) {
        userinfoService.delete(ids);
        return R.success();
    }

    @PostMapping("/update/status/{userinfoId}")
    @ApiOperation("修改状态")
    public R updateStatus(@ApiParam("用户编号") @PathVariable int userinfoId) {
        userinfoService.updateStatus(userinfoId);
        return R.success();
    }

    @PostMapping("/auth")
    @ApiOperation("实名认证")
    public R auth(@RequestBody AuthOV form) {
        userinfoService.auth(form);
        return R.success();
    }

    @GetMapping("/exam/info/{userinfoId}")
    @ApiOperation("审核详情")
    public R examInfo(@ApiParam("用户编号") @PathVariable int userinfoId) {
        ExamDto dto = BeanConvertUtils.copyBean(userinfoService.getById(userinfoId), ExamDto.class);
        return R.success(dto);
    }

    @PostMapping("/exam")
    @ApiOperation("审核实名")
    public R exam(@RequestBody ExamOV form) {
        userinfoService.exam(form);
        return R.success();
    }

    @GetMapping("/info/{userinfoId}")
    @ApiOperation("会员详情")
    public R info(@ApiParam("用户编号") @PathVariable int userinfoId) {
        Userinfo userinfo = userinfoService.getById(userinfoId);
        UserinfoDto dto = BeanConvertUtils.copyBean(userinfo, UserinfoDto.class);
        return R.success(dto);
    }
}
